<template>
  <el-card>
    <el-form ref="queryFormRef" :inline="true" :model="queryFormModel" label-width="80px">
      <el-form-item label="账号" prop="username">
        <el-input v-model="queryFormModel.username" placeholder="请输入用户名" clearable />
      </el-form-item>
      <el-form-item label="部门" prop="dept_id">
        <el-select v-model="queryFormModel.dept_id" placeholder="请选择部门">
          <el-option v-for="dept in departments" :key="dept.id" :label="dept.name" :value="dept.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="角色" prop="role_id">
        <el-select v-model="queryFormModel.role_id" placeholder="请选择角色">
          <el-option v-for="role in roles" :key="role.id" :label="role.name" :value="role.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryFormModel.status" placeholder="请选择状态">
          <el-option label="启用" value="1" />
          <el-option label="禁用" value="2" />
        </el-select>
      </el-form-item>
    </el-form>
    <div class="text-right">
      <el-button type="primary" icon="Search" @click="onSubmit">查询</el-button>
      <el-button icon="RefreshLeft" @click="onReset">重置</el-button>
    </div>
  </el-card>
</template>

<script lang="ts" setup>
import type { FormInstance } from 'element-plus';
import { reactive, ref } from 'vue';
import useCommonStore from "@/store/common"
import { storeToRefs } from "pinia"

var commonStore = useCommonStore()
var { roles, departments } = storeToRefs(commonStore)
var emit = defineEmits(["on-reset", "on-submit"])

var queryFormModel = reactive({
  username: "",
  dept_id: "",
  role_id: "",
  status: ""
})

var queryFormRef = ref<FormInstance>()

// 查询
function onSubmit() {
  emit("on-submit", queryFormModel)
}
// 重置
function onReset() {
  queryFormRef.value?.resetFields()
  emit("on-reset", queryFormModel)
}
</script>

<style lang="scss" scoped>
.el-input {
  --el-input-width: 200px;
}

.el-select {
  --el-select-width: 200px;
}
</style>
